package com.baiyun.bs.service.impl;

import com.baiyun.bs.domain.Course;
import com.baiyun.bs.repository.CourseMapper;
import com.baiyun.bs.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public List<Course> getAllCourses(Course course) {
        try {
            return courseMapper.getAllCourses(course);
        } catch (Exception e) {
            // 可以打印异常信息或者进行适当的处理
            e.printStackTrace();
            throw new RuntimeException("获取课程列表失败", e);
        }
    }
    @Override
    public Course getCourseById(Long courseId) {
        return courseMapper.getCourseById(courseId);
    }

    @Override
    public void addCourse(Course course) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createTime = sdf.format(new Date());
        course.setCreateTime(createTime);
        // 设置创建时间等其他逻辑
        courseMapper.insertCourse(course);
    }

    @Override
    public void updateCourse(Course course) {
        courseMapper.updateCourse(course);
    }

    @Override
    public void deleteCourse(Long courseId) {
        courseMapper.deleteCourse(courseId);
    }

}

